package com.wm.ad_navi_new.ui.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.wm.ad_navi_new.R
import com.wm.ad_navi_new.contract.SettingContract
import com.wm.ad_navi_new.presenter.SettingPresenter
import com.wm.ad_navi_new.ui.fragment.SettingFragment


class SettingActivity : AppCompatActivity(),SettingContract.ISettingView {

    private var presenter: SettingContract.ISettingPresenter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_setting)
        replaceFragment(SettingFragment())

        presenter = SettingPresenter(this)

        presenter?.onLoadData()
    }

    private fun replaceFragment(fragment: Fragment) {
        val fragmentManager: FragmentManager = supportFragmentManager
        val transaction: FragmentTransaction = fragmentManager.beginTransaction()
        transaction.replace(R.id.fragment_container, fragment)
        transaction.commit()
    }

    override fun showLoading() {

    }

    override fun hideLoading() {

    }

    override fun onDestroy() {
        super.onDestroy()
        if (presenter != null) {
            presenter?.onViewDestroy() // 清除Presenter对View的引用
            presenter = null // 设置为null，确保不在持有Presenter的实例
        }
    }

}